package server;

import common.GameState;


public class GameStateWaitingForPlayers extends GameControllerState {
	
	
	@Override
	public void initializeState(GameController c) {
		super.initializeState(c);
		game.setPlayingState(GameState.WaitingForPlayers);
		
	}

	
	@Override
	public void playerAttached(UpdateablePlayer player) {
		game.setMessage("new player " + player.GetName() + " joined the game");
		
		UpdateablePlayer[] players = game.getUpdateablePlayer();
		if (players != null && players.length == GameController.MAX_PLAYERS) {
			System.out.println("now we have enough players. trigger state change");
			
			controller.setState(new GameStateGetReady());
		} else {
			
			System.out.println("players count: " + (players == null ? "(null)" : players.length));
		}
	}
	
	
	@Override
	public void playerDetached(UpdateablePlayer player) {
		game.setMessage("player " + player.GetName() + " has left the game again");
	}


}
